package com.yanqu.road.server.cmd.cross.marriage;

import com.yanqu.road.pb.marriage.MarriageProto;
import com.yanqu.road.server.cmd.base.AbstractServerCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.manger.marriage.MarriageMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;


@Cmd(code = Protocol.S_CROSS_UNION_MARRIAGE_CANCEL_RESP, desc = "跨服商会联姻取消响应")
public class CrossUnionMarriageCancelRespCmd extends AbstractServerCommand {
	private long userId;
	private String childUid;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		MarriageProto.MarriageApplyCancelRespMsg reqMsg = MarriageProto.MarriageApplyCancelRespMsg.parseFrom(packet.getBytes());
		ret = reqMsg.getRet();
		childUid = reqMsg.getChildUid();
		userId = packet.getPlayerId();
		return true;
	}

	@Override
	public void execute(YanQuMessage packet) throws Exception {
		if(0 == ret){
			MarriageMgr.crossUnionMarriageCancelResponse(userId, childUid);
		}

		MarriageProto.MarriageApplyCancelRespMsg.Builder respMsg = MarriageProto.MarriageApplyCancelRespMsg.newBuilder();
		respMsg.setRet(ret);
		GamePlayer player = GamePlayerMgr.getOnlinePlayer(userId);
		if(null != player){
			player.sendPacket(Protocol.U_MARRIAGE_APPLY_CANCEL, respMsg);
		}
	}

	@Override
	public void sendData(YanQuMessage packet) throws Exception {

	}
}
